/* 
 * File:   main.cpp
 * Author: Usama, Max, Andy
 *
 * Created on February 4, 2011, 9:41 AM
 */

#include "FreeList.h"
#include "BlockLinkedList.h"
#include "Disk.h"
#include "Block.h"
#include "Directory.h"
#include "DirectoryEntry.h"
#include "FCB.h"
#include "File.h"
#include <string>
#include <cstdlib>
#include <vector>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <cstdlib>


using namespace std;

/*
 * 
 */
int main(int argc, char** argv) {

    FreeList *testFreeList;// = new FreeList("Disk1.disk",true);
    Directory* testDirectory = NULL;

    testFreeList = new FreeList("Disk1.disk",true);
    testDirectory = new Directory(testFreeList,true);
    File::Initialize(testFreeList, testDirectory);

    File* f1 = new File("Mario", 'w');

    //File::List();

                //cout << "Please enter number of bytes to write to file f1: ";
                int numBytesWrite1 = 700;
                //cin >> numBytesWrite1;


                char* writeBuffer1 = new char[numBytesWrite1];
                for(int i = 0; i < numBytesWrite1; i++)
                    writeBuffer1[i] = 'B';

                cout << endl;
                cout << "Attemping to write bytes to file f1..." << endl;

                cout << "NumBytes: " << numBytesWrite1 << "; Bytes: " << writeBuffer1 << ";" << endl;

                int writeResult1 = f1->Write(writeBuffer1, numBytesWrite1);
                if (writeResult1 == numBytesWrite1)
                    cout << "Write Successfully wrote " << numBytesWrite1 << " bytes to File f1!" << endl;
                else
                    cout << "Write Failed!";

//    int option = -1;
//
//    do {
//        cout << "Please select an option: " << endl;
//        cout << "0) Exit program" << endl;
//        cout << "1) Initialize new Directory" << endl;
//        cout << "2) Initialize existing Directory" << endl;
//        cout << "3) Open Directory" << endl;
//
//        // File stuff
//        // File 1
//        cout << "4) Create File 1" << endl;
//        cout << "5) Open File 1" << endl;
//        cout << "6) Switch File 1 read/write mode" << endl;
//        cout << "7) Write to File 1" << endl;
//        cout << "8) Read from File 1" << endl;
//
//        // File 2
//        cout << "9) Create File 2" << endl;
//        cout << "10) Open File 2" << endl;
//        cout << "11) Switch File 2 read/write mode" << endl;
//        cout << "12) Write to File 2" << endl;
//        cout << "13) Read from File 2" << endl;
//
//        cout << "14) List File Entries" << endl;
//        cout << "15) Check to see if File Exists" << endl;
//        cout << "Enter an option: ";
//
//        //assign user input to variable option
//        cin >> option;
//
//        // run selected option
//        switch (option) {
//            case 1 :
//                testFreeList = new FreeList("Disk1.disk",true);
//                testDirectory = new Directory(testFreeList,true);
//                File::Initialize(testFreeList, testDirectory);
//            break;
//            case 2 :
//                testFreeList = new FreeList("Disk1.disk",false);
//                testDirectory = new Directory(testFreeList,false);
//                File::Initialize(testFreeList, testDirectory);
//            break;
//            case 3 :
//                if(testDirectory == NULL)
//                    printf("Directory not initialized\n");
//                else testDirectory->Open();
//            break;
//
//            case 4: // Create a File
//                printf("Enter filename of file to create : ");
//                char* tempFileName1 = new char[DirectoryEntry::FILENAME_LENGTH];
//                cin >> tempFileName1;
//
//                File* f1 = new File(tempFileName1, 'w');
//                printf("File f1 Successfully Created");
//                break;
//
//            case 5: // Open a File
//                cout << "Please enter the mode you would like to open File f1 as:";
//                char mode1;
//                cin >> mode1;
//                f1->Open(mode1);
//                cout << endl;
//                printf("File f1 Opened Successfully");
//                break;
//
//            case 6:
//                cout << "Please enter the mode you would like to switch File f1 to: ";
//                char mode2;
//                cin >> mode2;
//                f1->SwitchMode(mode2);
//                break;
//
//            case 7: // Write to File
//                cout << "Please enter number of bytes to write to file f1: ";
//                int numBytesWrite1;
//                cin >> numBytesWrite1;
//
//                char* writeBuffer1 = new char[numBytesWrite1];
//                for(int i = 0; i < numBytesWrite1; i++)
//                    writeBuffer1[i] = i;
//
//                cout << endl;
//                cout << "Attemping to write bytes to file f1..." << endl;
//
//                cout << "NumBytes: " << numBytesWrite1 << "; Bytes: " << writeBuffer1 << ";" << endl;
//
//                int writeResult1 = f1->Write(writeBuffer1, numBytesWrite1);
//                if (writeResult1 == numBytesWrite1)
//                    cout << "Write Successfully wrote " << numBytesWrite1 << " bytes to File f1!" << endl;
//                else
//                    cout << "Write Failed!";
//
//                break;
//            case 8: // Read from File
//                cout << "Please enter number of bytes to read from file f1: ";
//                int numBytesRead1;
//                cin >> numBytesRead1;
//
//                char* readBuffer1 = new char[numBytesRead1];
//                f1->Read(readBuffer1,numBytesRead1);
//
//                cout << "Bytes read from f1:" << endl;
//                cout << readBuffer1 << endl;
//
//                break;
//
//            case 9: // Create a File
//                printf("Enter filename of file to create : ");
//                char* tempFileName2 = new char[DirectoryEntry::FILENAME_LENGTH];
//                cin >> tempFileName2;
//
//                File* f2 = new File(tempFileName2, 'w');
//                printf("File f2 Successfully Created");
//                break;
//
//            case 10: // Open a File
//                cout << "Please enter the mode you would like to open File f2 as:";
//                char mode3;
//                cin >> mode3;
//                f1->Open(mode3);
//                cout << endl;
//                printf("File f2 Opened Successfully");
//                break;
//
//            case 11:
//                cout << "Please enter the mode you would like to switch File f2 to: ";
//                char mode4;
//                cin >> mode4;
//                f2->SwitchMode(mode4);
//                break;
//
//            case 12: // Write to File
//                cout << "Please enter number of bytes to write to file f2: ";
//                int numBytesWrite2;
//                cin >> numBytesWrite2;
//
//                char* writeBuffer2 = new char[numBytesWrite2];
//                for(int i = 0; i < numBytesWrite2; i++)
//                    writeBuffer2[i] = i;
//
//                cout << endl;
//                cout << "Attemping to write bytes to file f2..." << endl;
//
//                int writeResult2 = f1->Write(writeBuffer2, numBytesWrite2);
//                if (writeResult2 == numBytesWrite2)
//                    cout << "Write Successfully wrote " << numBytesWrite2 << " bytes to File f2!" << endl;
//                else
//                    cout << "Write Failed!";
//
//                break;
//            case 13: // Read from File
//                cout << "Please enter number of bytes to read from file f2: ";
//                int numBytesRead2;
//                cin >> numBytesRead2;
//
//                char* readBuffer2 = new char[numBytesRead2];
//                f2->Read(readBuffer2,numBytesRead2);
//
//                cout << "Bytes read from f2:" << endl;
//                cout << readBuffer2 << endl;
//
//                break;
//
//            case 14: // List File Entries
//                cout << "Files Entries:" << endl;
//                File::List();
//                break;
//
//            case 15: // Check if File Exists
//                printf("Enter filename of file to check : ");
//                char* tempFileName5 = new char[DirectoryEntry::FILENAME_LENGTH];
//                cin >> tempFileName5;
//
//                File::Exists(tempFileName5);
//                break;
//        }
//        cout << endl;
//
//    }
//    // loop until option 8 is selected
//    while (option != 0);

    return 0;

}

